<?php
/**
 * Created by PhpStorm.
 * User: songdewei
 * Date: 2017/10/10
 * Time: 下午3:20
 */

namespace App\WeChat\WxApi;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

class WxMenuApi extends WxApi
{
    /**
     * 创建自定义菜单
     * @param $menus
     * @return mixed
     * @throws \Exception
     */
    public static function create($menus)
    {
        $uri = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".self::getAccessToken();
        $request = new Request('POST', $uri, [], $menus);
        $client  = new Client();
        $response = $client->send($request);
        if ($response->getStatusCode() == 200) {
            return $response->getBody();
        }
        return false;
    }

    /**
     * 删除自定义菜单
     * @return mixed
     * @throws \Exception
     */
    public static function delete()
    {
        $uri = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=".self::getAccessToken();
        $client = new Client();
        $response = $client->get($uri);
        if ($response->getStatusCode() == 200) {
            return $response->getBody();
        }
        return false;
    }

    /**
     * @return mixed
     * @throws \Exception
     */
    public static function searchMenu()
    {
        $uri = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=".self::getAccessToken();
        $client = new Client();
        $response = $client->get($uri);
        if ($response->getStatusCode() == 200) {
            return $response->getBody();
        }
        return false;
    }
}
